home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / syntax / ocaml.vim < prev    next >
Encoding:
Text File  |  2001-09-06  |  12.1 KB  |  284 lines

  1. " Vim syntax file
  2. " Language:     OCaml
  3. " Filenames:    *.ml *.mli *.mll *.mly
  4. " Maintainers:  Markus Mottl      <markus@oefai.at>
  5. "               Karl-Heinz Sylla  <Karl-Heinz.Sylla@gmd.de>
  6. " URL:          http://www.ai.univie.ac.at/~markus/vim/syntax/ocaml.vim
  7. " Last Change:  2001 Sep 01 - Fixed small bug with '\''  (MM)
  8. "               2001 Aug 29 - Added rules for scripting directives  (MM)
  9. "               2001 Aug 28 - Upgraded URL & mail address  (MM)
  10. "               2001 Apr 26 - upgraded for new Vim version  (MM)
  11.  
  12. " For version 5.x: Clear all syntax items
  13. " For version 6.x: Quit when a syntax file was already loaded
  14. if version < 600
  15.   syntax clear
  16. elseif exists("b:current_syntax")
  17.   finish
  18. endif
  19.  
  20. " OCaml is case sensitive.
  21. syn case match
  22.  
  23. " Script headers highlighted like comments
  24. syn match    ocamlComment   "^#!.*"
  25.  
  26. " Scripting directives
  27. syn match    ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|trace\|untrace\|untrace_all\|print_depth\|print_length\)\>"
  28.  
  29. " lowercase identifier - the standard way to match
  30. syn match    ocamlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/
  31.  
  32. syn match    ocamlKeyChar    "|"
  33.  
  34. " Errors
  35. syn match    ocamlBraceErr   "}"
  36. syn match    ocamlBrackErr   "\]"
  37. syn match    ocamlParenErr   ")"
  38. syn match    ocamlArrErr     "|]"
  39.  
  40. syn match    ocamlCommentErr "\*)"
  41.  
  42. syn match    ocamlCountErr   "\<downto\>"
  43. syn match    ocamlCountErr   "\<to\>"
  44. syn match    ocamlDoErr      "\<do\>"
  45. syn match    ocamlDoneErr    "\<done\>"
  46. syn match    ocamlThenErr    "\<then\>"
  47.  
  48. " Error-highlighting of "end" without synchronization:
  49. " as keyword or as error (default)
  50. if exists("ocaml_noend_error")
  51.   syn match    ocamlKeyword    "\<end\>"
  52. else
  53.   syn match    ocamlEndErr     "\<end\>"
  54. endif
  55.  
  56. " Some convenient clusters
  57. syn cluster  ocamlAllErrs contains=ocamlBraceErr,ocamlBrackErr,ocamlParenErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
  58.  
  59. syn cluster  ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
  60.  
  61. syn cluster  ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlPreMPRestr,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod
  62.  
  63.  
  64. " Enclosing delimiters
  65. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="(" matchgroup=ocamlKeyword end=")" contains=ALLBUT,@ocamlContained,ocamlParenErr
  66. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="{" matchgroup=ocamlKeyword end="}"  contains=ALLBUT,@ocamlContained,ocamlBraceErr
  67. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="\[" matchgroup=ocamlKeyword end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr
  68. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="\[|" matchgroup=ocamlKeyword end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr
  69.  
  70.  
  71. " Comments
  72. syn region   ocamlComment start="(\*" end="\*)" contains=ocamlComment,ocamlTodo
  73. syn keyword  ocamlTodo contained TODO FIXME XXX
  74.  
  75.  
  76. " Objects
  77. syn region   ocamlEnd matchgroup=ocamlKeyword start="\<object\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  78.  
  79.  
  80. " Blocks
  81. syn region   ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  82.  
  83.  
  84. " "for"
  85. syn region   ocamlNone matchgroup=ocamlKeyword start="\<for\>" matchgroup=ocamlKeyword end="\<\(to\|downto\)\>" contains=ALLBUT,@ocamlContained,ocamlCountErr
  86.  
  87.  
  88. " "do"
  89. syn region   ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr
  90.  
  91.  
  92. " "if"
  93. syn region   ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr
  94.  
  95.  
  96. "" Modules
  97.  
  98. " "struct"
  99. syn region   ocamlStruct matchgroup=ocamlModule start="\<struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  100.  
  101. " "sig"
  102. syn region   ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
  103. syn region   ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr
  104.  
  105. " "open"
  106. syn region   ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment
  107.  
  108. " "include"
  109. syn region   ocamlNone matchgroup=ocamlKeyword start="\<include\>" matchgroup=ocamlModPath end="\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contains=o@ocamlAllErrs,camlComment
  110.  
  111. " "module" - somewhat complicated stuff ;-)
  112. syn region   ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef
  113. syn region   ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|="me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS
  114. syn region   ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1
  115. syn match    ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr
  116.  
  117. syn region   ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr
  118.  
  119. syn region   ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3
  120. syn region   ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
  121. syn region   ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2
  122. syn match    ocamlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
  123. syn match  ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
  124. syn region  ocamlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
  125. syn match   ocamlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith
  126.  
  127. syn region  ocamlFuncWith start="("me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith
  128. syn region  ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  129.  
  130. syn match    ocamlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
  131. syn region   ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith
  132. syn match    ocamlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest
  133. syn region   ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
  134.  
  135. " "module type"
  136. syn region   ocamlKeyword start="\<module\s*type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
  137. syn match    ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
  138.  
  139. syn keyword  ocamlKeyword  and as assert class
  140. syn keyword  ocamlKeyword  constraint else
  141. syn keyword  ocamlKeyword  exception external fun function
  142. syn keyword  ocamlKeyword  in inherit initializer
  143. syn keyword  ocamlKeyword  land lazy let match
  144. syn keyword  ocamlKeyword  method mutable new of
  145. syn keyword  ocamlKeyword  parser private raise rec
  146. syn keyword  ocamlKeyword  try type
  147. syn keyword  ocamlKeyword  val virtual when while with
  148.  
  149. syn keyword  ocamlType     array bool char exn float format int
  150. syn keyword  ocamlType     list option string unit
  151.  
  152. syn keyword  ocamlOperator asr lor lsl lsr lxor mod not or
  153.  
  154. syn keyword  ocamlBoolean      true false
  155. syn match    ocamlConstructor  "(\s*)"
  156. syn match    ocamlConstructor  "\[\s*\]"
  157. syn match    ocamlConstructor  "\[|\s*>|]"
  158. syn match    ocamlConstructor  "\[<\s*>\]"
  159. syn match    ocamlConstructor  "\u\(\w\|'\)*\>"
  160.  
  161. " Polymorphic variants
  162. syn match    ocamlConstructor  "`\w\(\w\|'\)*\>"
  163.  
  164. " Module prefix
  165. syn match    ocamlModPath      "\u\(\w\|'\)*\."he=e-1
  166.  
  167. syn match    ocamlCharacter    "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'"
  168. syn match    ocamlCharErr      "'\\\d\d'\|'\\\d'"
  169. syn match    ocamlCharErr      "'\\[^\'ntbr]'"
  170. syn region   ocamlString       start=+"+ skip=+\\\\\|\\"+ end=+"+
  171.  
  172. syn match    ocamlFunDef       "->"
  173. syn match    ocamlRefAssign    ":="
  174. syn match    ocamlTopStop      ";;"
  175. syn match    ocamlOperator     "\^"
  176. syn match    ocamlOperator     "::"
  177. syn match    ocamlOperator     "<-"
  178. syn match    ocamlAnyVar       "\<_\>"
  179. syn match    ocamlKeyChar      "!"
  180. syn match    ocamlKeyChar      "|[^\]]"me=e-1
  181. syn match    ocamlKeyChar      ";"
  182. syn match    ocamlKeyChar      "\~"
  183. syn match    ocamlKeyChar      "?"
  184. syn match    ocamlKeyChar      "\*"
  185. syn match    ocamlKeyChar      "="
  186.  
  187. syn match    ocamlNumber        "\<-\=\d\+\>"
  188. syn match    ocamlNumber        "\<-\=0[x|X]\x\+\>"
  189. syn match    ocamlNumber        "\<-\=0[o|O]\o\+\>"
  190. syn match    ocamlNumber        "\<-\=0[b|B][01]\+\>"
  191. syn match    ocamlFloat         "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>"
  192.  
  193. " Labels
  194. syn match    ocamlLabel        "\~\(\l\|_\)\(\w\|'\)*"lc=1
  195. syn match    ocamlLabel        "?\(\l\|_\)\(\w\|'\)*"lc=1
  196. syn region   ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr
  197.  
  198.  
  199. " Synchronization
  200. syn sync minlines=50
  201. syn sync maxlines=500
  202.  
  203. syn sync match ocamlDoSync      grouphere  ocamlDo      "\<do\>"
  204. syn sync match ocamlDoSync      groupthere ocamlDo      "\<done\>"
  205. syn sync match ocamlEndSync     grouphere  ocamlEnd     "\<\(begin\|object\)\>"
  206. syn sync match ocamlEndSync     groupthere ocamlEnd     "\<end\>"
  207. syn sync match ocamlStructSync  grouphere  ocamlStruct  "\<struct\>"
  208. syn sync match ocamlStructSync  groupthere ocamlStruct  "\<end\>"
  209. syn sync match ocamlSigSync     grouphere  ocamlSig     "\<sig\>"
  210. syn sync match ocamlSigSync     groupthere ocamlSig     "\<end\>"
  211.  
  212. " Define the default highlighting.
  213. " For version 5.7 and earlier: only when not done already
  214. " For version 5.8 and later: only when an item doesn't have highlighting yet
  215. if version >= 508 || !exists("did_ocaml_syntax_inits")
  216.   if version < 508
  217.     let did_ocaml_syntax_inits = 1
  218.     command -nargs=+ HiLink hi link <args>
  219.   else
  220.     command -nargs=+ HiLink hi def link <args>
  221.   endif
  222.  
  223.   HiLink ocamlBraceErr     Error
  224.   HiLink ocamlBrackErr     Error
  225.   HiLink ocamlParenErr     Error
  226.   HiLink ocamlArrErr       Error
  227.  
  228.   HiLink ocamlCommentErr   Error
  229.  
  230.   HiLink ocamlCountErr     Error
  231.   HiLink ocamlDoErr        Error
  232.   HiLink ocamlDoneErr      Error
  233.   HiLink ocamlEndErr       Error
  234.   HiLink ocamlThenErr      Error
  235.  
  236.   HiLink ocamlCharErr      Error
  237.  
  238.   HiLink ocamlComment      Comment
  239.  
  240.   HiLink ocamlModPath      Include
  241.   HiLink ocamlModule       Include
  242.   HiLink ocamlModParam1    Include
  243.   HiLink ocamlModType      Include
  244.   HiLink ocamlMPRestr3     Include
  245.   HiLink ocamlFullMod      Include
  246.   HiLink ocamlModTypeRestr Include
  247.   HiLink ocamlWith         Include
  248.   HiLink ocamlMTDef        Include
  249.  
  250.   HiLink ocamlScript       Include
  251.  
  252.   HiLink ocamlConstructor  Constant
  253.  
  254.   HiLink ocamlModPreRHS    Keyword
  255.   HiLink ocamlMPRestr2     Keyword
  256.   HiLink ocamlKeyword      Keyword
  257.   HiLink ocamlFunDef       Keyword
  258.   HiLink ocamlRefAssign    Keyword
  259.   HiLink ocamlKeyChar      Keyword
  260.   HiLink ocamlAnyVar       Keyword
  261.   HiLink ocamlTopStop      Keyword
  262.   HiLink ocamlOperator     Keyword
  263.  
  264.   HiLink ocamlBoolean      Boolean
  265.   HiLink ocamlCharacter    Character
  266.   HiLink ocamlNumber       Number
  267.   HiLink ocamlFloat        Float
  268.   HiLink ocamlString       String
  269.  
  270.   HiLink ocamlLabel        Identifier
  271.  
  272.   HiLink ocamlType         Type
  273.  
  274.   HiLink ocamlTodo         Todo
  275.  
  276.   HiLink ocamlEncl         Keyword
  277.  
  278.   delcommand HiLink
  279. endif
  280.  
  281. let b:current_syntax = "ocaml"
  282.  
  283. " vim: ts=28
  284.